$(document).ready(function(){
	pic();
	window.onresize = function(){pic();};
//注册和登录链接变换
	$(".adRegi").click(function(){
		$("#login").hide("normal");
		$("#register").show("normal");
		$(".adRegi").css("visibility","hidden");
		$("#adLog").css("visibility","visible");
	})
	$("#adLog").click(function(){
		$("#register").hide("normal");
		$("#login").show("normal");
		$("#adLog").css("visibility","hidden");
		$(".adRegi").css("visibility","visible");
	})
//当输入框有动作时的变化的实现
	boxvar("username",".labelClass:eq(0)");
	boxvar("password",".labelClass:eq(1)");
	boxvar("rusername",".tdHead:eq(0)");
	boxvar("rpassword1",".tdHead:eq(1)");
	boxvar("rpassword2",".tdHead:eq(2)");
	boxvar("remail",".tdHead:eq(3)");
	boxvar("rcaptcha",".tdHead:eq(4)");
//注册信息验证实现
	registerIdentify();
//注册失败跳会注册页面
	isRegister();
})
//输入框有动作的变化函数
var boxvar = function(clickId,changeClass){
	var j_clickId = "#" + clickId;
	function checkVal(){
		if(document.getElementById(clickId).value.length != 0)
			return true;
		else
			return false;
	}
	if(checkVal()){
		$(changeClass).css("visibility","hidden");
	}
	$(j_clickId).load(function(){
		$(changeClass).css("visibility","hidden");
	});
	$(j_clickId).focus(function(){
		$(j_clickId).css("background-image","url('img/box1.jpg')");
		if(!checkVal())
		$(changeClass).css("color","#aaa");
		else
		$(changeClass).css("visibility","hidden");
	});
	$(j_clickId).keyup(function(){
		if(checkVal())
			$(changeClass).css("visibility","hidden");
		else{
			$(changeClass).css("visibility","visible");
			$(changeClass).css("color","#aaa");
		}
	});
	$(j_clickId).blur(function(){
		if(!checkVal()){
			$(changeClass).css("visibility","visible");
			$(changeClass).css("color","#333");
			$(j_clickId).css("background-image","url('img/box2.jpg')");
		}
		else
			$(changeClass).css("visibility","hidden");
	});
	$(j_clickId).click(function(){
		$(j_clickId).css("background-image","url('img/box1.jpg')");
		if(checkVal())
			$(changeClass).css("visibility","hidden");
		else{
			$(changeClass).css("visibility","visible");
			$(changeClass).css("color","#aaa");
		}
	});
}
//注册信息验证函数
var registerIdentify = function(){
	//注册提示格式
//picNum: 1 表示填写正确 2表示输入为空 3表示输入有误
var showtips = function(rclass,text,picNum){
	if(picNum == 1){
		$(rclass).css({'border-color':'#FFF','background-color':'#FFF','color':'#111','font-size':'0.9em','padding-left':'3px'});
		$(rclass).html("<img src='img/yesPic.png'></img>"+text);
	}
	if(picNum == 2){
		$(rclass).css({'border-color':'#C86','background-color':'#FEF','color':'#C03','font-size':'0.9em','padding-left':'3px'});
		$(rclass).html("<img src='img/attentionPic.png'></img>"+text);
	}
	if(picNum == 3){
		$(rclass).css({'border-color':'#C86','background-color':'#FEF','color':'#C03','font-size':'0.9em','padding-left':'3px'});
		$(rclass).html("<img src='img/noPic.png'></img>"+text);
	}
	}
//用户名验证
	VD_name = function(){
		$("#rusername").blur(function(){
			with(document.getElementById("rusername")){
				if(value.length < 1){
				showtips(".rtips:eq(0)","请填写用户名",2);
				return false;
				}
				else if(value.length < 8 || value.length > 15){
				showtips(".rtips:eq(0)","用户名填写有误,长度范围为8~15",3);
				return false;
				}
				else{
				showtips(".rtips:eq(0)","填写正确",1);
				return true;
				}
			}
		});
	};
//密码验证
	VD_password1 = function(){
		$("#rpassword1").blur(function(){
			with(document.getElementById("rpassword1")){
				if(value.length < 1){
				showtips(".rtips:eq(1)","请填写密码",2);
				return false;
				}
				else if(value.length > 20){
				showtips(".rtips:eq(1)","密码填写有误，长度不得超过20",3);
				return false;
				}
				else{
				showtips(".rtips:eq(1)","填写正确",1);
				return true;
				}
			}
		});
	};
//密码确认验证
	VD_password2 = function(){
		$("#rpassword2").blur(function(){
			with(document.getElementById("rpassword2")){
				if(value.length < 1){
				showtips(".rtips:eq(2)","请确认密码",2);
				return false;
				}
				else if(value != document.getElementById("rpassword1").value){
				showtips(".rtips:eq(2)","两次密码输入不一致，请重新填写",3);
				return false;
				}
				else{
				showtips(".rtips:eq(2)","填写正确",1);
				return true;
				}
			}
		});
	};
//邮箱确认
	VD_email = function(){
		$("#remail").blur(function(){
			with(document.getElementById("remail")){
				var apos=value.indexOf("@");
				var dotpos=value.lastIndexOf(".");
				if(value.length < 1){
				showtips(".rtips:eq(3)","请输入邮箱",2);
				return false;
				}
				else if(apos<1||dotpos-apos<2){
				showtips(".rtips:eq(3)","邮箱填写有误，请重新填写",3);
				return false;
				}
				else{
				showtips(".rtips:eq(3)","填写正确",1);
				return true;
				}
			}
		});
	};
	
	VD_name();
	VD_password1();
	VD_password2();
	VD_email();
	/*if(VD_name() && VD_password1() && VD_password2() && VD_email()){
		$("#register .submit input").click(function(){
			$("#register .submit input").css("disabled","false");
	});
	}
	else{
		
			$("#register .submit input").css("disabled","true");
			alert("填写有误！");
		}*/
}

//logo图片的处理
function pic(){
	var w = window.innerWidth;
	var logow = w * 0.84 * 0.5 * 0.8;
	var logoh = 55/382 * logow;
	$("#logo").css("width",logow);
	$("#logo").css("height",logoh);
	var gifw = w * 0.84 * 0.5 *0.7;
	$("#logingif").css("width",gifw);
}
//判断是处于登录页还是注册页
function isRegister(){
	if(location.hash == '#register'){
		$(".adRegi").click();
	}
}
